//
//  BaseTabBarController.m
//  PhotographyStudi
//
//  Created by 叶一枫 on 2017/5/10.
//  Copyright © 2017年 叶一枫. All rights reserved.
//

#import "BaseTabBarController.h"

typedef void(^myBlock)();

@interface BaseTabBarController ()<UITabBarControllerDelegate>
@property(nonatomic,strong)BSTabBar*BSTabBar;

@property(nonatomic,strong)NSArray*titleArr;

@property(nonatomic,strong)NSArray*leftItemArr;
@property(nonatomic,strong)NSArray*rightItemArr;



@end

@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    [self initTabBar];
    
    [self initNaviItem];
    self.navigationItem.leftBarButtonItem = self.leftItemArr[self.selectedIndex];
    self.navigationItem.rightBarButtonItem = self.rightItemArr[self.selectedIndex];
    
    self.titleArr = @[@"我的",@"聊天",@"我的摄影展",@"收藏",@"设置"];
    self.navigationItem.title = self.titleArr[self.selectedIndex];
    
}

-(void)initNaviItem{
    
    UIBarButtonItem *leftItem0 = [[UIBarButtonItem alloc]initWithTitle:@"扫一扫" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    leftItem0.tag = 0;
    UIBarButtonItem *rightItem0 = [[UIBarButtonItem alloc]initWithTitle:@"添加" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    rightItem0.tag = 1;

    UIBarButtonItem *leftItem1 = [[UIBarButtonItem alloc]initWithTitle:@"扫一扫" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    leftItem1.tag = 2;

    UIBarButtonItem *rightItem1 = [[UIBarButtonItem alloc]initWithTitle:@"聊天" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    rightItem1.tag = 3;

    UIBarButtonItem *leftItem2 = [[UIBarButtonItem alloc]initWithTitle:@"切换试图" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    leftItem2.tag = 4;
    UIBarButtonItem *rightItem2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(click:)];
    rightItem2.tag = 5;
    
    UIBarButtonItem *leftItem3 = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    leftItem3.tag = 6;

    UIBarButtonItem *rightItem3 = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    rightItem3.tag = 7;
    
    UIBarButtonItem *leftItem4 = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    leftItem4.tag = 8;
    UIBarButtonItem *rightItem4 = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(click:)];
    rightItem4.tag = 9;
    
    self.leftItemArr = @[leftItem0,leftItem1,leftItem2,leftItem3,leftItem4];
    self.rightItemArr = @[rightItem0,rightItem1,rightItem2,rightItem3,rightItem4];


}

-(void)click:(UIBarButtonItem*)sender{
    
    
}

-(void)initTabBar{
    
    /*
     tabbar 图片尺寸为 30*30   60*60   90*90
     */
    
    self.delegate = self;
    self.BSTabBar = [[BSTabBar alloc] initWithFrame:CGRectMake(0, -15, self.view.frame.size.width, 64)];
    self.BSTabBar.delegate = self;
    [self setValue:self.BSTabBar forKey:@"tabBar"];
    self.selectedIndex = 2;
    self.tabBarItem.badgeValue = @"2";
    [self.BSTabBar setBarTintColor:[UIColor colorWithHexString:MAIN_COLOR]];
    
}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    tabBarController.navigationItem.title = self.titleArr[self.selectedIndex];
    
    self.navigationItem.leftBarButtonItem = self.leftItemArr[self.selectedIndex];
    self.navigationItem.rightBarButtonItem = self.rightItemArr[self.selectedIndex];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
